﻿using System;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;

public static class GameUtility
{
    public const string IngameSceneName = "Ingame";
    public const string ReadyRoomSceneName = "ReadyRoom";

    public static GameObject CreateObject(string prefabAssetName)
    {
        return CreateObject(prefabAssetName, Vector3.zero);
    }

    public static T CreateObject<T>(string prefabAssetName)
    {
        return CreateObject<T>(prefabAssetName, Vector3.zero);
    }

    public static GameObject CreateObject(string prefabAssetName, Vector3 position)
    {
        Transform transform = CreateObject<Transform>(prefabAssetName, position);
        return ((transform == null) ? null : transform.gameObject);
    }

    public static T CreateObject<T>(string prefabAssetName, Vector3 position)
    {
        Asset prefabAsset = AssetManager.GetPrefabAsset(prefabAssetName);
        if ((prefabAsset == null) || (prefabAsset.gameObject.GetComponent<T>() == null))
        {
            object[] args = new object[] { prefabAssetName, typeof(T) };
            Debug.LogErrorFormat("Could not find prefab '{0}' with type '{1}'", args);
            return default(T);
        }
        if (!NetworkUtility.isServer)
        {
            object[] objArray2 = new object[] { prefabAssetName };
            Debug.LogWarningFormat("Creating network object '{0}' on client, it's not allowed.", objArray2);
        }
        return Level.Spawn(prefabAsset.gameObject, position).GetComponent<T>();
    }

    public static bool IsDemoVersion()
    {
        if (Application.isEditor)
        {
            return false;
        }
        return !File.Exists(Path.GetDirectoryName(Application.dataPath) + "/steam_api.dll");
    }

    public static bool isIngameScene
    {
        get
        {
            return (SceneManager.GetActiveScene().name == "Ingame");
        }
    }

    public static bool isLevelEditorScene
    {
        get
        {
            return (SceneManager.GetActiveScene().name == "LevelEditor");
        }
    }

    public static bool isReadyRoomScene
    {
        get
        {
            return (SceneManager.GetActiveScene().name == "ReadyRoom");
        }
    }
}

